package com.ttg.web.juc;


import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Time 2023/2/17 14:24
 * @Version 1.0.0
 * @Author liujie
 * @Destination  溢出选择策略
 */
public class CallerRunsPolicyForDiy implements RejectedExecutionHandler {


    /**
     * Executes task r in the caller's thread, unless the executor
     * has been shut down, in which case the task is discarded.
     *
     * @param r the runnable task requested to be executed
     * @param e the executor attempting to execute this task
     */
    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {

        if(r instanceof ListenableFutureTaskTemp){
            ListenableFutureTaskTemp listenableFutureTask=(ListenableFutureTaskTemp) r;
            listenableFutureTask.setIsSkip(true);//越过异步通知 由线程业务自己操作
        }
    }
}
 